package com.xbs.controller.enterprise;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.EpOrderDetailEntity;
import com.xbs.service.enterprise.EpOrderDetailService;
import com.xbs.utils.EnterpriseUtils;
@WebServlet("/backstage/enterpriseOrder/detail1")
public class EpOrderDetailerController extends BaseServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		PrintWriter out=resp.getWriter();
		String id=req.getParameter("id");
		EnterpriseUtils util=new EnterpriseUtils();
		EpOrderDetailService service=new EpOrderDetailService();
		List<EpOrderDetailEntity> orders=service.getOrderById(id);
		double sum=0.0;
		Integer rentDay=0;
		if(orders.get(0).getEo_order_status().equals("租赁中")){
			rentDay=util.daysBetween(orders.get(0).getEo_reserve_get_time(), new Date(System.currentTimeMillis()));
			for(EpOrderDetailEntity o:orders){
				sum+=o.getRent_money()*o.getCar_model_number();
			}
			sum*=rentDay;
		};
		if(orders.get(0).getEo_order_status().equals("已预订")){
			for(EpOrderDetailEntity o:orders){
				sum+=o.getRent_money()*o.getCar_model_number();
			}
		};
		if(orders.get(0).getEo_order_status().equals("已完成")){
			rentDay=util.daysBetween(orders.get(0).getEo_reserve_get_time(),orders.get(0).getEo_fact_return_time());
			for(EpOrderDetailEntity o:orders){
				sum+=o.getRent_money()*o.getCar_model_number();
			}
			sum*=rentDay;
		};
		resp.setCharacterEncoding("utf-8");
		String str="<div class=\"container w100\" style=\"background-color: #f6fafb;padding-top:40px;\"><span class=\"return\">返回</span>"+
				"		<div class=\" w1200 center\" style=\"height:auto;\">"+
				"		<div class=\"o-order\">"+
				"		<div class=\"o-order-top clear\">"+
				"			<h3 class=\"fl\">"+orders.get(0).getEo_order_status()+"</h3>"+
				"			<p class=\"fl o-sump\">订单总价</p>"+
				"			<p class=\"fl o-sum\">￥"+sum+"</p>"+
				"		</div>"+
				"		<div class=\"o-order-center\">"+
				"			<p>订单编号:"+orders.get(0).getEo_order_id()+" |租车企业："+orders.get(0).getEnterprise_name()+" |租期:"+rentDay+"天</p>"+
				"		</div>"+
				"		</div>"+
				"	</div>"+
				"	<div class=\"o-basic clear w1200 center\" style=\"height:auto\">"+
				"		<h3>基本信息</h3>";
		StringBuffer sb=new StringBuffer(str);
		for(EpOrderDetailEntity o:orders){
			String returnTime="";
			if(o.getEo_fact_return_time()!=null){
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				returnTime=sdf.format(o.getEo_fact_return_time());
			}
			sb.append("		<div class=\"fl o-basic-con\" style=\"margin-top:20px;\">"+
					"			<div class=\"o-basic-pic\">"+
					"				<img width=\"100%\" height=\"100%\" src="+req.getContextPath()+"/"+o.getCar_model_image()+">"+
					"			</div>"+
					"			<p class=\"fl\"> "+o.getCar_model_name()+"</p>"+
					"			<p class=\"fl\"> "+o.getCar_model_fuel_type()+"</p>"+
					"			<p class=\"fl\"> 乘坐"+o.getCar_model_seating()+"人</p>"+
					"		</div>"+
					"		<div class=\"o-basic-right fl\" style=\"margin-top:20px;\">"+
					"			<p>取车时间：<span>"+o.getEo_reserve_get_time()+"</span></p>"+
					"			<p>还车时间：<span>"+returnTime+"</span></p>"+
					"		</div>");
		}
		sb.append("	</div>").append("	<div class=\"o-prisedetail w1200 center\" style=\"height:auto\"><h3>费用明细</h3><ul>");
		for(EpOrderDetailEntity o:orders){
			sb.append("			<li class=\"clear\"> "+
					"				<p class=\"fl\">"+o.getCar_model_name()+"</p>"+
					"				<p class=\"fr\" style=\"padding-right:20px;\">"+o.getCar_model_number()+"X"+o.getRent_money()*o.getCompany_discount()+"x"+rentDay+"x2=<span style=\"font: bold 24px/24px arial;color: #f60;\">"+o.getCar_model_number()*o.getRent_money()*o.getCompany_discount()*rentDay+"</span></p>"+
					"			</li>");
		}
		sb.append("		</ul>"+
				"	</div>"+
				"</div>");
						
			/*	"	<div class=\"o-prisedetail w1200 center\" style=\"height:auto\">"+
				"		<h3>费用明细</h3>"+
				"		<ul>"+
				"			<li class=\"clear\"> "+
				"				<p class=\"fl\">车辆租赁费及门店服务费</p>"+
				"				<p class=\"fr\" style=\"padding-right:20px;\">88x2=<span style=\"font: bold 24px/24px arial;color: #f60;\">￥176</span></p>"+
				"			</li>"+
				"			<li class=\"clear\"> "+
				"				<p class=\"fl\">车辆租赁费及门店服务费</p>"+
				"				<p class=\"fr\" style=\"padding-right:20px;\">88x2=<span style=\"font: bold 24px/24px arial;color: #f60;\">￥176</span></p>"+
				"			</li>"+
				"			<li class=\"clear\"> "+
				"				<p class=\"fl\">车辆租赁费及门店服务费</p>"+
				"				<p class=\"fr\" style=\"padding-right:20px;\">88x2=<span style=\"font: bold 24px/24px arial;color: #f60;\">￥176</span></p>"+
				"			</li>"+
				"			<li class=\"o-last-li\">"+
				"				<p class=\"fr\" style=\"text-align: right;\">订单总价:<span>￥276</span></p>"+
				"			</li>"+
				"		</ul>"+
				"	</div>"+
				"</div>";*/
		out.println(sb);
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req,resp);
	}
}
